<template>
	<div>
		<my-header :header="header"></my-header>
		<div class="login-out" v-on:click="loginOut()">
			<img src="../assets/img/logout@3x.png" />
		</div>
		<div class="form">
			<div class="error">
				已提交名单：{{user.todaycount}}
			</div>
			<div class="row-1">
				<div class="label">
					<label>推广人员</label>
				</div>
				<div class="info">
					<label>{{user.agentname}}</label>
				</div>
			</div>
			<div class="row-1">
				<div class="label">
					<label>地址</label>
				</div>
				<div class="info">
					<label>{{user.location}}</label>
				</div>
			</div>
			<div class="button submit">
				<div v-on:click="confirm()">
					确认
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	import myHeader from '../components/my-header'
	import $ from '../assets/js/jquery.min.js'
	import { mapState, mapActions } from 'vuex'
	import { USER_SIGNOUT} from '../store/user'

	export default {
		name: 'info',
		data() {
			return {
				header: {
					cnTitle: "线下推广系统",
					enTitle: "Offline Promotion",
					cnStyle: {
						fontSize: "32px",
						marginTop: "15px"
					},
					enStyle: {
						fontSize: "18px"
					}
				}
			}
		},
		created: function() {
			var _that = this;
      var urlroot = urlchange;
      var url = urlroot+'/OMLeadKeyinRequest';
			$.ajax({
				type: 'GET',
				url: url,
				dataType: "jsonp",
				data: {
					"key": "omleadkeyin",
					//"parameters": "token=" + _that.user.token,
					"ContentType": "application/x-www-form-urlencoded",
					"fun": "callbackFun",
					//"token": "z6fYujYV/QAKehzfyAI8ZxAVWto="
           "token": _that.user.token,
          //"token":"undefined",
          "ClientIp":""
				},
				jsonpCallback: "callbackFun",
				success: function(result) {
					//var jsonResult = JSON.parse(result)[0];
           var jsonResult = result.ResultInfo;
					if(result.IsSuccess==false) {
            alert("token无效,请重新登录");
             _that.$router.push('/login')
          }
         else {
            if(result.ResultInfo.msgcode >= 0) {} else {
              alert("token无效,请重新登录");
               _that.$router.push('/login');
            }

					}
				},
				error: function(error) {
					alert("系统异常");
				}
			});
		},
		methods: {
			...mapActions([USER_SIGNOUT]),
			confirm: function() {
			  var _that=this;
        //var url = "http://192.168.87.162:80/VmdService.Host.OpenService/OMLeadKeyinRequest";
        //var urlroot = API_ROOT;
        var urlroot = urlchange;
        var url = urlroot+'/OMLeadKeyinRequest';
        $.ajax({
          type: 'GET',
          url: url,
          dataType: "jsonp",
          data: {
            "key": "omlogout",
            //"parameters": "token=" + _that.user.token,
            "ContentType": "application/x-www-form-urlencoded",
            "fun": "callbackFun",
            //"token": "z6fYujYV/QAKehzfyAI8ZxAVWto="
            "token": _that.user.token
            //"token":"undefined"
          },
          jsonpCallback: "callbackFun",
          success: function(result) {
            var jsonResult = result;
            if(result.ResultInfo.msgcode>=0) {
              // alert("token无效，请重新登录"
              _that.$router.push('/entering');
            }
            else{
                 alert("token无效，请重新登录");
              _that.$router.push('/login');
            }
          },
          error: function(error) {
            alert("系统异常");
          }
        });
			},
			loginOut: function() {
				if(!confirm("您确定要退出吗？")) {
					return false;
				}
				var _that = this;
				//var url = 'http://192.168.236.31:9013/home/jsonp';
        //var url = 'http://192.168.87.162:80/VmdService.Host.OpenService/OMLoginoutRequest';
        //var urlroot = API_ROOT;
        var urlroot = urlchange;
        var url = urlroot+'/OMLoginoutRequest';
				$.ajax({
					type: 'GET',
					url: url,
					dataType: "jsonp",
					data: {
						"key": "omlogout",
						//"parameters": "token=" + _that.user.token,
						"ContentType": "application/x-www-form-urlencoded",
					"fun": "callbackFun",
						//"token": "z6fYujYV/QAKehzfyAI8ZxAVWto="
            "token": _that.user.token
					},
					jsonpCallback: "callbackFun",
					success: function(result) {
						if(result.IsSuccess) {
							_that.USER_SIGNOUT();
							_that.$router.push('/login');
						} else {
							alert("操作失败");
						}
					},
					error: function(error) {
						alert("系统异常");
					}
				});
			}
		},
		computed: {
			...mapState(['user'])
		},
		components: { myHeader }
	}
</script>
